package gui.component;

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;

/**
 *
 * @author Tom
 */
public class PasswordInput 
{
    public static String showInput(JFrame parent)
    {
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        JLabel label = new JLabel("Saisissez votre mot de passe:");
        JPasswordField pass = new JPasswordField();
        panel.add(label,BorderLayout.NORTH);
        panel.add(pass,BorderLayout.SOUTH);
        String[] options = new String[]{"OK", "Annuler"};
        int option = JOptionPane.showOptionDialog(parent, panel, "",
                                 JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE,
                                 null, options, options[1]);
        if(option == 0) // pressing OK button
        {
            return new String(pass.getPassword());
        }
        else
        {
            return null;
        }        
    }
}
